import java.util.Scanner;

public class fib {
    //递归练习
    //输出一个数的每一位
    public static void print(int n){
        if(n < 10){
            System.out.println(n);
            return;
        }
        print(n / 10);
        System.out.println(n % 10);
    }
    //1-n 递归求和
    public static int sum(int n){
        if(n == 1){
            return 1;
        }
        return n + sum(n - 1);

    }
    //各位数字相加求和
    public static int add(int n){
        if(n < 10){
            return n;
        }
        return add(n / 10) + n % 10;
    }
    //斐波那契数列
    public static int fib(int n){
            if(n == 1){
                return 0;
            } else if(n == 2){
                return 1;
            }
            return fib(n - 1) + fib(n - 2);
    }
    //使用递归效率很低，此处使用循环实现
    public static int fib1(int n){
        int f1  = 0;
        int f2 = 1;
        int f3 = 0;
        for(int i = 3; i <= n; i++){
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }
    //数组
    public static void main1(String[] args) {
        int [] arr1 = new int[]{1,2,3,4};
        int [] arr2 = new int[10];
        arr2 = new int[]{1, 2, 3, 4};
        //普通for循环
        for(int i = 0; i < arr1.length; i++){
            System.out.print(arr1[i] + " ");
        }
        System.out.println();
        //增强for循环
        for( int x : arr2){
            System.out.print(x + " ");
        }
    }
    //递归
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        print(123);
        System.out.println(sum(10));
        System.out.println(add(10));
        int n = in.nextInt();
        for(int i = 1; i <= n; i++){
            System.out.print(fib(i) + " ");
        }
        System.out.println();
        for(int i = 1; i <= n; i++){
            System.out.print(fib(i) + " ");
        }
    }
}
